package com.lwb.ztx.news.model;

import com.lwb.ztx.api.Api;
import com.lwb.ztx.bean.NewsAndBannerBean;
import com.lwb.ztx.bean.NewsBean;
import com.lwb.ztx.utils.LogUtils;
import com.lwb.ztx.utils.OkHttpUtils;

import java.util.List;

/**
 * Created by luweibin on 2016/5/27.
 */
public class NewsListModelImpl implements NewsListModel {
    private OnLoadListener listener;

    public NewsListModelImpl(OnLoadListener listener) {
        this.listener = listener;
    }

    @Override
    public void loadNews(String url, final int page) {
        OkHttpUtils.ResultCallback<String> loadNewsCallback = new OkHttpUtils.ResultCallback<String>() {
            @Override
            public void onSuccess(String response) {
                NewsAndBannerBean newsBeanList = NewsJsonUtils.readJsonNewsBeans(response);
                listener.onSuccess(newsBeanList, page);
            }

            @Override
            public void onFailure(Exception e) {
                listener.onFailure();
            }
        };
        OkHttpUtils.get(url, loadNewsCallback);
    }

    public interface OnLoadListener {
        void onSuccess(NewsAndBannerBean beans, int page);
        void onFailure();
    }

}
